package com.ymatou.iapi.selleraccount.testcase;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.selleraccount.service.QuerySellerRoleListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.database.model.YmlCreateRole;
import com.ymttest.database.sqlwapper.YmlCreateRoleIMapper;

/**
 * 
 * @author chencan
 * 子账号角色查询
 */

public class Tc_QuerySellerRoleList {
	private static QuerySellerRoleListCall querySellerRoleListCall;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("业务说明：子账号角色查询");
	}

	@Before
	public void caseUp() {
		querySellerRoleListCall = new QuerySellerRoleListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(querySellerRoleListCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QuerySellerRoleList_001 (){
		Logger.start(true, "子账号角色查询");
		try{
			
			JSONObject retBea = new QuerySellerRoleListCall().callAndGetReturnData();
			JSONObject data = retBea.getJSONObject("Data").getJSONArray("SellerRoleDtos").getJSONObject(1);
			JSONObject menudtos = data.getJSONArray("SellerRoleMenuDtos").getJSONObject(0);
			
			int code = retBea.getInt("Code");
			Boolean success = retBea.getBoolean("Success");
			int roleid = data.getInt("Roleid");
			int sellerid = data.getInt("Sellerid");
			String rolename = data.getString("RoleName");
			
			List<YmlCreateRole> accounts = new YmlCreateRoleIMapper().selectCreateRoleSellerId(rolename);
			YmlCreateRole firsts =accounts.get(0);
			int roleids = firsts.getRoleId();
			int sellerids = firsts.getSellerID();
			String rolenames = firsts.getRoleName();
			
			
			Logger.verifyEquals(200, code, "code返回结果");
			Logger.verifyEquals(true, success, "返回结果状态");
			Logger.verifyEquals(roleid, roleids, "角色ID");
			Logger.verifyEquals(sellerid, sellerids, "主账号ID");
			Logger.verifyEquals(rolename, rolenames, "角色名称");
			Logger.verifyNotNull(menudtos, "角色权限不为空");

			
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QuerySellerRoleList_002 (){
		Logger.start(true, "子账号角色查询--主账号不存在");
		try{
			
			int sellerid = 338999;
			
			Map<String,Object> map1 = new HashMap<String,Object>();
			map1.put("SellerId",sellerid);
			
			JSONObject retBea = new QuerySellerRoleListCall().callAndGetReturnData(map1);
			JSONObject data = retBea.getJSONObject("Data");
			String roledtos = data.getString("SellerRoleDtos");
			
			int code = retBea.getInt("Code");
			Boolean success = retBea.getBoolean("Success");
			
			
			
			Logger.verifyEquals(200, code, "code返回结果");
			Logger.verifyEquals(true, success, "返回结果状态");
			Logger.verifyEquals("[]", roledtos, "返回结果为空");

			
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QuerySellerRoleList_003 (){
		Logger.start(true, "子账号角色查询--参数异常");
		try{
			
			int sellerid = 0;
			
			Map<String,Object> map1 = new HashMap<String,Object>();
			map1.put("SellerId",sellerid);
			
			JSONObject retBea = new QuerySellerRoleListCall().callAndGetReturnData(map1);
			String data =retBea.getString("Data");
			String message = retBea.getString("ErrorMessage");
			
			int code = retBea.getInt("Code");
			Boolean success = retBea.getBoolean("Success");
			
			
			
			Logger.verifyEquals(500, code, "code返回结果");
			Logger.verifyEquals(false, success, "返回结果状态");
			Logger.verifyEquals("null", data, "返回结果为null");
			Logger.verifyEquals("参数有误", message, "错误描述");

			
		}catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QuerySellerRoleList_004 (){
		Logger.start(true, "子账号角色查询--分页错误");
		try{
			
			int size = 0;
			int index = 0;
			
			Map<String,Object> map1 = new HashMap<String,Object>();
			map1.put("PageSize",size);
			map1.put("PageIndex",index);
			
			JSONObject retBea = new QuerySellerRoleListCall().callAndGetReturnData(map1);
			JSONObject data = retBea.getJSONObject("Data");
			String roledtos = data.getString("SellerRoleDtos");
			
			int code = retBea.getInt("Code");
			Boolean success = retBea.getBoolean("Success");
			
			
			
			Logger.verifyEquals(200, code, "code返回结果");
			Logger.verifyEquals(true, success, "返回结果状态");
			Logger.verifyEquals("[]", roledtos, "返回结果为空");

			
		}catch (Exception e) {
			e.printStackTrace();
		}
	}

}
